import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { GameConst } from "../../../../component/gconst/GameConst";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SuitQiWindow } from "./SuitQiWindow";
import { SSuitSkillInfo } from "../../../../../Message/Game/SSuitSkillInfo";
import { SuitSkillUpgradeConfig } from "../../../resource/SuitSkillUpgradeConfig";
import { SSuitSkillUpgradeRate } from "../../../../../Message/Game/SSuitSkillUpgradeRate";
import { Cache } from "../../../cache/Cache";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ESavvyDirection } from "../../../../../Message/Game/ESavvyDirection";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SkillConfig } from "../../../resource/SkillConfig";
import { TSkill } from "../../../../../Message/Db/Tables/TSkill";
import { ObjCreate } from "../../common/ObjCreate";
import { BaseItem } from "../../common/BaseItem";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { LongProgressBar } from "../LongProgressBar";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LayerManager } from "../../../manager/LayerManager";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class SuitSkillWindow
    
    export  class SuitSkillWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._maxAcc = GameConst.MaxAccumulation;
            this._maxTimes = GameConst.SuitSkillUpgradeMaxTimes;
            this.setSize(605, 425);
            this.title = Language.getString(35970);
            this.titleHeight = 28;
            return;
        }

        /* internal  */onSetLinkClick(arg1): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFeedModuleShow));
            return;
        }

        public get qiWindow(): SuitQiWindow
        {
            return this._qiWindow;
        }

        public updateBySuitSkillInfo(arg1: SSuitSkillInfo): void
        {
            if (arg1) 
            {
                this._costQi = SuitSkillUpgradeConfig.instance.getMaxAccumulationByLevel(arg1.level);
                this.updateCostTxt();
                this.updateSkillById(arg1.skillId);
                this._skillLevelTxt.text = "LV." + arg1.level;
                this._qiLevelTxt.text = "LV." + arg1.level;
                this._leftTimes = this._maxTimes - arg1.times;
                this._dayTimesTxt.text = this._leftTimes + "/" + this._maxTimes;
                if (this._leftTimes != 0) 
                {
                    this._noTimesTxt.visible = false;
                }
                else 
                {
                    this._noTimesTxt.visible = true;
                }
            }
            return;
        }

        public updateBySkillRate(arg1: SSuitSkillUpgradeRate): void
        {
            if (arg1) 
            {
                this.updateSuccessRate(arg1);
                this._successBar.setValue(arg1.rate, 100);
            }
            return;
        }

        public updateAccumulation(arg1: int): void
        {
            this.updateCostTxt();
            this._totalQiTxt.text = arg1.toString();
            this._qiValueTxt.text = arg1 + "/" + this._maxAcc;
            this._qiValueBar.setValue(arg1, this._maxAcc);
            if (this._qiWindow && this._qiWindow.isHide == false) 
            {
                this._qiWindow.updateAccumulation(arg1, this._maxAcc);
            }
            return;
        }

        /* internal  */updateCostTxt(): void
        {
            if (this._costQi > Cache.instance.role.accumulation) 
            {
                this._costQiTxt.htmlText = HTMLUtil.addColor(this._costQi.toString(), "#ff0000");
            }
            else 
            {
                this._costQiTxt.htmlText = HTMLUtil.addColor(this._costQi.toString(), "#00ff00");
            }
            return;
        }

        /* internal  */updateSuccessRate(arg1: SSuitSkillUpgradeRate): void
        {
            var loc1=arg1.rate;
            if (arg1.direction.value() != ESavvyDirection._ESavvyDirectionAdd) 
            {
                this._upBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.RangeDecline);
                this._upTxt.htmlText = HTMLUtil.addColor(Language.getString(36101), "#ff0000");
            }
            else 
            {
                this._upBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.RangeRaise);
                this._upTxt.htmlText = HTMLUtil.addColor(Language.getString(36100), "#00ff00");
            }
            this._successRate = loc1;
            this._rateTxt.text = loc1 + "%";
            return;
        }

        /* internal  */updateSkillById(arg1: int): void
        {
            this._skill = SkillConfig.instance.getInfoByName(arg1);
            if (this._skill) 
            {
                this._skillNameTxt.text = this._skill.skillName;
                this._nextSkill = SkillConfig.instance.getInfoByName(arg1 + 1);
                this._skillItem.source = this._skill.skillIcon + ".jpg";
                this._skillDescTxt.htmlText = this.getSkillDesc(this._skill);
                if (this._skill.skillLevel == 100) 
                {
                    this._skillNextDescTxt.htmlText = Language.getString(36220);
                    return;
                }
                if (this._skill.skillLevel == 150) 
                {
                    this._skillNextDescTxt.htmlText = Language.getString(36223);
                    return;
                }
                if (this._skill.skillLevel == 200) 
                {
                    this._skillNextDescTxt.htmlText = Language.getString(36221);
                    return;
                }
            }
            if (this._nextSkill) 
            {
                this._skillNextDescTxt.htmlText = this.getSkillDesc(this._nextSkill);
            }
            return;
        }

        /* internal  */getSkillDesc(arg1: TSkill): string
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (arg1) 
            {
                if (arg1.useType != 1) 
                {
                    if (arg1.useType == 16) 
                    {
                        loc2 = Language.getString(35994);
                    }
                }
                else 
                {
                    loc2 = Language.getString(35993);
                }
                if (arg1.cooldownTime != 0) 
                {
                    loc3 = arg1.cooldownTime / 1000 + Language.getString(35996);
                }
                else 
                {
                    loc3 = Language.getString(35995);
                }
                loc1 = Language.getStringByParam(35997, loc2, loc3, arg1.skillDescription);
                loc1 = "<textFormat leading=\'5\'>" + loc1 + "</textFormat>";
            }
            return loc1;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._leftPanel = new Object /* flash.display.Sprite */();
            this._leftPanel.x = 17;
            this._leftPanel.y = 39;
            this.addChild(this._leftPanel);
            ObjCreate.createBg(0, 0, 197, 375, this._leftPanel);
            ObjCreate.createBg(13, 14, 68, 68, this._leftPanel);
            this._skillItem = new BaseItem();
            this._skillItem.setSize(62, 62);
            this._skillItem.move(16, 17);
            this._leftPanel.addChild(this._skillItem);
            this._skillNameTxt = ObjCreate.createTextField("", 85, 30, 105, 20, this._leftPanel, new GTextFormat(FontUtil.songtiName, 18, 15788607, true));
            this._skillNameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._skillLevelTxt = ObjCreate.createTextField("", 85, 60, 105, 20, this._leftPanel, new GTextFormat(FontUtil.songtiName, 18, 16742658, true));
            this._skillLevelTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._skillDescTxt = ObjCreate.createTextField("", 15, 100, 175, 110, this._leftPanel);
            this._skillDescTxt.multiline = true;
            this._skillDescTxt.wordWrap = true;
            this._skillDescTxt.mouseWheelEnabled = false;
            this._skillDescTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createBg(9, 220, 180, 2, this._leftPanel, ImagesConst.SplitLine);
            ObjCreate.createTextField(Language.getString(35972), 15, 225, 105, 20, this._leftPanel, new GTextFormat(FontUtil.songtiName, 18, 15788607, true));
            this._skillNextDescTxt = ObjCreate.createTextField("", 15, 250, 175, 110, this._leftPanel);
            this._skillNextDescTxt.multiline = true;
            this._skillNextDescTxt.wordWrap = true;
            this._skillNextDescTxt.mouseWheelEnabled = false;
            this._skillNextDescTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._rightPanel = new Object /* flash.display.Sprite */();
            this._rightPanel.x = 217;
            this._rightPanel.y = 39;
            this.addChild(this._rightPanel);
            ObjCreate.createBg(0, 0, 370, 207, this._rightPanel);
            ObjCreate.createBg(0, 268, 370, 108, this._rightPanel);
            this._rightPanel.addChild(new GImageBitmap(ImagesConst.QiLevel, 12, 13));
            this._qiLevelTxt = ObjCreate.createTextField("", 115, 13, 105, 30, this._rightPanel, new GTextFormat(FontUtil.songtiName, 18, 65280, true));
            this._rightPanel.addChild(new GImageBitmap("equipment_successRate.png", 92, 43));
            this._rateTxt = ObjCreate.createTextField("", 177, 45, 50, 30, this._rightPanel, new GTextFormat(FontUtil.songtiName, 18, 65280, true));
            this._upBitmap = GlobalClass.getBitmap(ImagesConst.RangeRaise);
            this._upBitmap.width = 11;
            this._upBitmap.height = 17;
            this._upBitmap.x = 227;
            this._upBitmap.y = 48;
            this._rightPanel.addChild(this._upBitmap);
            this._upTxt = ObjCreate.createTextField("", 240, 49, 105, 30, this._rightPanel);
            this._upTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._successBar = new LongProgressBar();
            this._successBar.progressBarClass = ImagesConst.Shengmingtiao;
            this._successBar.setBgSize(265, 14);
            this._successBar.move(16, 70);
            this._rightPanel.addChild(this._successBar);
            ObjCreate.createTextField(Language.getString(35974), 90, 105, 200, 20, this._rightPanel, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._costQiTxt = ObjCreate.createTextField("", 190, 105, 200, 20, this._rightPanel, new GTextFormat(FontUtil.songtiName, 12, 65280));
            ObjCreate.createTextField(Language.getString(35975), 90, 125, 200, 20, this._rightPanel, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._totalQiTxt = ObjCreate.createTextField("", 190, 125, 200, 20, this._rightPanel, new GTextFormat(FontUtil.songtiName, 12, 65280));
            ObjCreate.createBg(18, 155, 340, 2, this._rightPanel, ImagesConst.SplitLine);
            ObjCreate.createTextField(Language.getString(35976), 15, 175, 200, 20, this._rightPanel, GlobalStyle.textFormat2);
            this._dayTimesTxt = ObjCreate.createTextField("", 125, 175, 200, 20, this._rightPanel, GlobalStyle.textFormat6);
            this._noTimesTxt = ObjCreate.createTextField(Language.getString(35977), 150, 175, 200, 20, this._rightPanel, new GTextFormat(FontUtil.songtiName, 12, 16711680));
            this._upgradeBtn = ObjCreate.createGButton(Language.getString(35978), 290, 170, 70, 26, this._rightPanel);
            this._upgradeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onUpgradeBtnClickHandler);
            this._rightPanel.addChild(new GImageBitmap(ImagesConst.QiValue, 15, 222));
            this._qiValueTxt = ObjCreate.createTextField("", 95, 220, 100, 30, this._rightPanel, new GTextFormat(FontUtil.songtiName, 18, 65280, true));
            this._qiValueTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._feedBtn = ObjCreate.createGButton(Language.getString(35979), 290, 215, 70, 26, this._rightPanel);
            this._feedBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onFeedBtnClickHandler);
            this._qiValueBar = new LongProgressBar();
            this._qiValueBar.progressBarClass = ImagesConst.Mofatiao;
            this._qiValueBar.setBgSize(265, 14);
            this._qiValueBar.move(16, 248);
            this._rightPanel.addChild(this._qiValueBar);
            this._tipTxt = ObjCreate.createTextField("", 8, 273, 355, 95, this._rightPanel);
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipTxt.multiline = true;
            this._tipTxt.wordWrap = true;
            this._tipTxt.mouseWheelEnabled = false;
            this._tipTxt.htmlText = Language.getString(35987);
            return;
        }

        /* internal  */onLinkClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            return;
        }

        /* internal  */onUpgradeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._skill) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SuitSkillUpgrade, this._successRate));
            }
            return;
        }

        /* internal  */onFeedBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._qiWindow == null) 
            {
                this._qiWindow = new SuitQiWindow(LayerManager.windowLayer);
            }
            this._qiWindow.updateAccumulation(Cache.instance.role.accumulation, this._maxAcc);
            this._qiWindow.show();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.updateBySuitSkillInfo(Cache.instance.role.suitSkillInfo);
            this.updateBySkillRate(Cache.instance.role.suitSkillUpgradeRate);
            this.updateAccumulation(Cache.instance.role.accumulation);
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            if (this._qiWindow) 
            {
                this._qiWindow.hide();
            }
            return;
        }

        /* internal */ /* var */_dayTimesTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_noTimesTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_upgradeBtn: GButton;

        /* internal */ /* var */_qiValueTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_feedBtn: GButton;

        /* internal */ /* var */_qiValueBar: LongProgressBar;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_skillDescTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_skill: TSkill;

        /* internal */ /* var */_nextSkill: TSkill;

        /* internal */ /* var */_successRate: int;

        /* internal */ /* var */_maxAcc: int;

        /* internal */ /* var */_maxTimes: int;

        /* internal */ /* var */_leftTimes: int;

        /* internal */ /* var */_costQi: int;

        /* internal */ /* var */_leftPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_skillItem: BaseItem;

        /* internal */ /* var */_skillNameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_skillLevelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_skillNextDescTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_linkTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rightPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_qiLevelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rateTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_qiWindow: SuitQiWindow;

        /* internal */ /* var */_upBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_upTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_successBar: LongProgressBar;

        /* internal */ /* var */_costQiTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_totalQiTxt: Object /* flash.text.TextField */;
    }
